<?php
class TankMonitors extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Organizations the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tank_monitors';
	}
	
	public function relations()
	{
		return array(
			'tanks'=>array(self::HAS_MANY, 'Tanks', 'tank_monitor_ID'),
		);
	}
	
	public function getMonitorMFG()
	{
		$connection = Yii::app()->db;
		$sql = "SELECT monitor_MFG FROM ".$this->tableName()." GROUP BY monitor_MFG";
		$command = $connection->createCommand($sql);
		$dataReader = $command->query();
		$res=array('-'=>'NO MONITOR');
		foreach($dataReader as $row)
		{
			$key=$row['monitor_MFG'];
			$res[$key]=$key;
		}
		return $res;
	}
	
	public function getModelsByMFG($mfg)
	{
		$connection = Yii::app()->db;
		$sql = "SELECT tank_monitor_ID, monitor_model FROM ".$this->tableName()." WHERE monitor_MFG='$mfg'";
		$command = $connection->createCommand($sql);
		$dataReader = $command->query();
		$res = array();
		foreach($dataReader as $row)
		{
			$key=$row['tank_monitor_ID'];
			$res[$key]=$row['monitor_model'];
		}
		return $res;
	}
}
?>
